from influxdb import InfluxDBClient
import pandas as pd
import sys
# reload(sys)
# sys.setdefaultencoding('uft-*8')
def DBcon():

    data=pd.read_csv("D:/hhxx2/aj/data/database_config.csv")
    InfHost=data['host'][0]
    InfPort=data['port'][0]
    InfUser = data['user'][0]
    InfPwd = data['passwd'][0]
    InfDB=data['db'][0]
    # 连接influxdb
    client = InfluxDBClient(InfHost, InfPort, InfUser, InfPwd, InfDB)
    # # 返回连接
    # # return MysqlCon, MysqlCur, Influxdb_Client
    json_body = [
        {
            "measurement": "students",
            "tags": {
                "stuid": "s123"
            },
            # "time": "2017-03-12T22:00:00Z",
            "fields": {
                "score": 89
            }
        }
    ]

    client.write_points(json_body)  # 写入数据
    # print(data)
    # print(client)
    result = client.query('select * from students;')
    print("Result: {0}".format(result))
    return result
# def MysqlClose():
#     MysqlCon.close()
#     MysqlCur.close()


if __name__ == '__main__':
    # MysqlCon, MysqlCur, Influxdb_Client, Redis_Client = DBcon()
     DBcon()